package cn.tedu.uep.petType.service.impl;

import cn.tedu.uep.petType.mapper.PetTypeMapper;
import cn.tedu.uep.petType.pojo.dto.PetTypeQuery;
import cn.tedu.uep.petType.pojo.dto.PetTypeSaveParam;
import cn.tedu.uep.petType.pojo.entity.PetType;
import cn.tedu.uep.petType.pojo.vo.PetTypeVO;
import cn.tedu.uep.petType.service.PetTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author HUAWEI
* 针对表【pet_type】的数据库操作Service实现
* @createDate 2024-12-18 15:06:31
*/
@Slf4j
@Service
public class PetTypeServiceImpl implements PetTypeService {

    @Autowired
    private PetTypeMapper petTypeMapper;
    @Override
    public List<PetTypeVO> selectPetType(PetTypeQuery petTypeQuery) {
        log.debug("加载宠物种类列表业务{}",petTypeQuery);
        List<PetTypeVO> list = petTypeMapper.selectPetType(petTypeQuery);
        return list;
    }

    @Override
    public void savePetType(PetTypeSaveParam petTypeSaveParam) {
        PetType petType = new PetType();
        BeanUtils.copyProperties(petTypeSaveParam,petType);
        if (petType.getPetTypeId()==null) {
            log.debug("新增宠物种类业务{}",petTypeSaveParam);
            petType.setCreateTime(new Date());
            petTypeMapper.savePetType(petType);
        }else{
            log.debug("修改宠物种类业务{}",petTypeSaveParam);
            petType.setUpdateTime(new Date());
            petTypeMapper.updatePetType(petType);
        }
    }

    @Override
    public void deletePetType(Integer petTypeId) {
        log.debug("删除宠物种类业务{}",petTypeId);
        petTypeMapper.deletePetType(petTypeId);
    }
}




